package cc.lirns.utils.result;

import cc.lirns.utils.result.entity.EntityResult;
import cc.lirns.utils.result.entity.TableResult;

/**
 * @author lirns
 * @date 2021/12/2 11:27
 */
public class ResultUtil {

    public static Result build(Integer code, String msg, Object data) {
        return new EntityResult(code, msg, data);
    }

    //    success
    public static Result success() {
        return build(ResultEnum.Success.code, ResultEnum.Success.msg, null);
    }

    public static Result success(String msg) {
        return build(ResultEnum.Success.code, msg, null);
    }

    public static Result success(Object data) {
        return build(ResultEnum.Success.code, ResultEnum.Success.msg, data);
    }

    public static Result success(String msg, Object data) {
        return build(ResultEnum.Success.code, msg, data);
    }

    //    fail
    public static Result fail() {
        return build(ResultEnum.Fail.code, ResultEnum.Fail.msg, null);
    }

    public static Result fail(String msg) {
        return build(ResultEnum.Fail.code, msg, null);
    }

    public static Result fail(Object data) {
        return build(ResultEnum.Fail.code, ResultEnum.Fail.msg, data);
    }

    public static Result fail(String msg, Object data) {
        return build(ResultEnum.Fail.code, msg, data);
    }

    //    error
    public static Result error() {
        return build(ResultEnum.Exception.code, ResultEnum.Fail.msg, null);
    }

    public static Result error(String msg) {
        return build(ResultEnum.Fail.code, msg, null);
    }

    public static Result error(Object data) {
        return build(ResultEnum.Fail.code, ResultEnum.Fail.msg, data);
    }

    public static Result error(String msg, Object data) {
        return build(ResultEnum.Fail.code, msg, data);
    }

    public static Result update(boolean changeFlag) {
        if (changeFlag) {
            return success();
        } else {
            return fail();
        }
    }

    public static Result update(Integer changeCount) {
        if (changeCount == 1) {
            return success();
        } else {
            return fail();
        }
    }

    public static Result update(Integer changeCount, Integer expectCount) {
        if (expectCount.equals(changeCount)) {
            return success();
        } else {
            return fail();
        }
    }

    public static Result table(Integer code, String msg, Object data, Integer count) {
        return new TableResult(code, msg, data, count);
    }

    public static Result table(Object data, Integer count) {
        return new TableResult(ResultEnum.LayUiDataTable.code, ResultEnum.LayUiDataTable.msg, data, count);
    }

}
